package com.xuecheng.search.controller;

import com.xuecheng.base.exception.ValidatedGroups;
import com.xuecheng.search.po.CourseIndex;
import com.xuecheng.search.service.ICourseIndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 勾新杰
 * @version 1.0
 * @description 课程索引接口
 * @date 2022/9/24 22:31
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/index")
@Api(tags = "课程信息索引接口")
public class CourseIndexController {

    /**
     * 索引服务
     */
    private final ICourseIndexService ICourseIndexService;

    /**
     * 添加课程索引
     * @param courseIndex 课程索引
     */
    @PostMapping("/course")
    @ApiOperation("指定课程索引添加一条文档")
    public Boolean save(@RequestBody @Validated(ValidatedGroups.Insert.class) CourseIndex courseIndex) {
        return ICourseIndexService.saveCourseIndexDoc(courseIndex);
    }

    /**
     * 更新课程索引
     * @param courseIndex 课程索引
     */
    @PutMapping("/course")
    @ApiOperation("指定课程索引更新一条文档")
    public Boolean update(@RequestBody @Validated(ValidatedGroups.Update.class) CourseIndex courseIndex) {
        return ICourseIndexService.updateCourseIndexDoc(courseIndex);
    }

    /**
     * 删除课程索引
     * @param id 课程id
     */
    @DeleteMapping("/course/{id}")
    @ApiOperation("指定课程索引删除一条文档")
    public Boolean delete(@PathVariable("id") String id) {
        return ICourseIndexService.deleteCourseIndexDoc(id);
    }
}
